package server.data;

import java.io.Serializable;
import java.text.ParseException;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 *
 * @author Danon
 */
public class Router implements Serializable {
    public final long serialVersionID = 1L;
    
    private int id;
    private String name;

    public Router(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    @Override
    public String toString() {
        return "Router{name:" + name + "; id:"+id+"}";
    }
    
    public static Router createFromDOM(Node node) {
        NamedNodeMap attr = node.getAttributes();
        Node idNode = attr.getNamedItem("id");
        int id = -1;
        if(idNode!=null) 
            id = Integer.parseInt(idNode.getTextContent());
        String name = null;
        if(node.hasChildNodes()) {
            name = node.getChildNodes().item(0).getTextContent();
        }
        if(name==null)
            throw new IllegalArgumentException();
        return new Router(id, name);
    }
}
